﻿@{
    ViewBag.Title = "Promotion";
}
@section scripts
{  
    <script src="@Url.Content("~/Scripts/shared/share.js")" type="text/javascript"></script> 
    <script src="@Url.Content("~/Scripts/shared/shown.js")" type="text/javascript"></script>
}
       
        <div class="mini-toolbar" style="padding:2px;border-top:0;border-left:0;border-right:0;"> 
            <table style="width:100%;">
                <tr>
                    <td style="width:100%;">
                        <a class="mini-button" id="fresh" name="fresh" iconCls="icon-search" onclick="search" plain="true">刷新</a>
                         <span class="separator"></span>
                        <a class="mini-button" id="modify" name="modify" iconCls="icon-edit" onclick="modify" plain="true">修改</a>
@*                        <a class="mini-button" id="copy" name="copy" iconCls="icon-reload" onclick="copy" plain="true">复制</a>
                        <a class="mini-button" id="new" name="new" iconCls="icon-new" onclick="newBill" plain="true">新增</a>
                         <a class="mini-button" id="delrow" name="delrow" iconCls="icon-remove" onclick="removeInfo" plain="true">删除</a>
                       <a class="mini-button" id="check" name="check" iconCls="icon-ok" onclick="check" plain="true">审核</a>*@
                         <span class="separator"></span>
                        <a class="mini-button" id="stop" name="stop" iconCls="icon-no" onclick="stop" plain="true">停止</a>
                        <span class="separator"></span>
                        <a class="mini-button" id="close" name="close" iconCls="icon-close" onclick="CloseWindow" plain="true">关闭</a>
                    </td>
                </tr>
            </table>       
        </div>        
        <table style="margin-bottom:4px;">
            <tr>
                <td width ="70px" align="right">单据日期：</td>
                <td width ="310px">
                    @Html.Partial("~/Views/Modular/dxDateRange.cshtml") 
                </td>
                <td width ="80px" align="right">编码或名称: </td>
                <td width ="150px" ><input class="mini-textbox" width ="150px" id ="FSearchKey" name = "FSearchKey" onkeypress="setkeyPress()" tabindex="1"/></td>
                <td width="70px" align="right">促销类型：</td>
                <td>
                    <input id="comType" name="comType" class="mini-combobox" style="width:80px;" textField="text" valueField="id"
                               url="../Coupon/GetPromotionType" value="0"  allowInput="true" tabindex="2"/>
                </td>
                <td width="70px" align="right">方案状态：</td>
                <td>
                    <input id="comStatus" name="comStatus" class="mini-combobox" style="width:80px;" textField="text" valueField="id"
                               data="fstatus" value="-100"  allowInput="true" tabindex="3"/>
                </td>
           </tr>
        </table>            
        <div class="mini-fit" >
            <div id="datagrid1" class="mini-datagrid" style="width:100%;height:100%;" pageSize="15"
                    borderStyle="border:1;" url="GetPromotionList"
                    allowCellSelect="true" allowCellEdit="true"showColumnsMenu="true"fitColumns="false"  
                    onrowdblclick="modify"  sortMode="client">
                <div property="columns">
                    <div type="checkcolumn" >选行</div>
                    <div type="indexcolumn" width="40" headerAlign="center" >序号</div>
                    <div field="FNumber" name="FNumber" width="100" headeralign="center" allowsort="true">编码</div>
                    <div field="FName" name="FName" width="150" headeralign="center" allowsort="true">方案名称</div>
                    <div field="FTypeName" name="FTypeName" width="150" headeralign="center" allowsort="true">促销类型</div>
                    <div field="FStartDate" name="FStartDate" width="80" headeralign="center" allowsort="true">开始日期</div>
                    <div field="FStartTime" name="FStartTime" width="80" headeralign="center"  allowsort="true">开始时间</div>
                    <div field="FEndDate" name="FEndDate" width="80" headeralign="center"  allowsort="true">结束日期</div>
                    <div field="FEndTime" name="FEndTime" width="80" headeralign="center" allowsort="true">结束时间</div>
                    <div field="FMembers" name="FMembers" width="80" headeralign="center" allowsort="true">促销人群</div>
                    <div field="FStates" name="FStates" width="80" headeralign="center" allowsort="true">方案状态</div>
                    <div field="FCorpName" name="FCorpName" width="100" headeralign="center" allowsort="true">公司名称</div>
                </div>
            </div>
            </div>
<script>
    var fstatus = [{ "id": "-100", "text": "全部" },
                { "id": "0", "text": "未审核" },
                { "id": "1", "text": " 已审核" },
                { "id": "-1", "text": "停用" }];

    function FormShown() {
        mini.parse();
        var toDay = new Date();
        mini.getbyName("FDate1").setValue(toDay);
        mini.getbyName("FDate2").setValue(toDay);
        LoadListData();
    }
    function setkeyPress() {
        LoadListData();
    }
    function LoadListData() {
        var sSystemAppID = parent.window.getSystemAppID();
        var nowDate = new Date();
        var date1 = mini.getbyName("FDate1").getFormValue() + ' 00:00:00';
        var date2 = mini.getbyName("FDate2").getFormValue() + ' 23:59:59';
        var json = "[{";
        json = json + "'mSystemAppID':" + "'" + sSystemAppID + "',";
        json = json + "'mSearch':" + "'" + mini.getbyName("FSearchKey").getValue() + "',";
        json = json + "'mDate1':" + "'" + date1 + "',";
        json = json + "'mDate2':" + "'" + date2 + "',";
        json = json + "'mState':" + "'" + mini.getbyName("comStatus").getValue() + "',";
        json = json + "'mType':" + "'" + mini.getbyName("comType").getValue() + "'";
        json = json + "}]";
        var grid = mini.get("datagrid1");
        grid.load({ mjson: json });
    }
    function search() {
        LoadListData();
    }
    function newBill() {
            mini.open({
                url: "/coupon/PromotionInfo",
                title: "促销方案", width: 620, height: 400,
                onload: function () {
                    var iframe = this.getIFrameEl();
                    var data = { action: "new", FItemID: "0"};
                    iframe.contentWindow.SetInfoData(data);
                },
                ondestroy: function (action) {
                    var grid = mini.get("datagrid1");
                    grid.reload();
                }
            });
    }
    function modify() {
        var grid = mini.get("datagrid1");
        var row = grid.getSelected();
        if (row) {
            //mini.open({
            //    url: "/coupon/PromotionInfo",
            //    title: "促销方案", width: 620, height: 400,
            //    onload: function () {
            //        var iframe = this.getIFrameEl();
            //        var data = { action: "edit", FItemID: row.FItemID };
            //        iframe.contentWindow.SetInfoData(data);
            //    },
            //    ondestroy: function (action) {
            //        LoadListData();
            //    }
            //});
            switch (row.FTypeID) {
                case 1:
                    parent.window.showTabByIdEx('44','GoodPromotion', '单品特价', '../Coupon/GoodPromotion?datatype=16&FItemID=' + row.FItemID);
                    break;
                case 2:
                    parent.window.showTabByIdEx('45','GoodDisPromotion', '直接折扣', '../Coupon/GoodDisPromotion?datatype=16&FItemID=' + row.FItemID);
                    break;
                case 3:
                    parent.window.showTabByIdEx('46','GoodCountDis', '第二件打折', '../Coupon/GoodCountDis?datatype=16&FItemID=' + row.FItemID);
                    break;
                case 4:
                    parent.window.showTabByIdEx('47','GoodAmountDis', '满额返现', '../Coupon/GoodAmountSub?datatype=16&FItemID=' + row.FItemID);
                    break;
                case 5:
                    parent.window.showTabByIdEx('48','GoodAmountBuy', '换购促销', '../Coupon/GoodAmountBuy?datatype=16&FItemID=' + row.FItemID);
                    break;
                case 6:
                    parent.window.showTabByIdEx('150','GoodPackPromotion', '商品组合', '../Coupon/GoodPackPromotion?datatype=16&FItemID=' + row.FItemID);
                    break;
                case 7:
                    parent.window.showTabByIdEx('148','Anniversary', '店庆活动', '../Coupon/Anniversary?datatype=16&FItemID=' + row.FItemID);
                    break;
                case 8:
                    parent.window.showTabByIdEx('162','CouponPromotion', '礼券促销', '../Coupon/CouponPromotion?datatype=16&FItemID=' + row.FItemID);
                    break;
                case 9:
                    parent.window.showTabByIdEx('164','GroupPurchase', '团购促销', '../Coupon/GroupPurchase?datatype=16&FItemID=' + row.FItemID);
                    break;
                case 10:
                    parent.window.showTabByIdEx('165','DownPrice', '砍价促销', '../Coupon/DownPrice?datatype=16&FItemID=' + row.FItemID);
                    break;
                case 11:
                    parent.window.showTabByIdEx('167','CouponShare', '分享送券', '../Coupon/CouponShare?datatype=16&FItemID=' + row.FItemID);
                    break;
                case 12:
                    parent.window.showTabByIdEx('201','GoodReducePrice', '削价促销', '../Coupon/GoodReducePrice?datatype=16&FItemID=' + row.FItemID);
                    break;
            }
        } else {
            mini.alert("请选中一条记录");
        }
    }

    function copy() {
        var grid = mini.get("datagrid1");
        var row = grid.getSelected();
        if (row) {
            mini.open({
                url: "/coupon/PromotionInfo",
                title: "促销方案", width: 620, height: 400,
                onload: function () {
                    var iframe = this.getIFrameEl();
                    var data = { action: "copy", FItemID: row.FItemID };
                    iframe.contentWindow.SetInfoData(data);
                },
                ondestroy: function (action) {
                    LoadListData();
                }
            });

        } else {
            mini.alert("请选中一条记录");
        }
    }

    function check() {
        var grid = mini.get("datagrid1");
        var row = grid.getSelected();
        if (row) {
            mini.confirm("确定要审核该方案吗？", "提示",
                function (action) {
                    if (action == "ok") {
                        var jsonstr = '[{"FItemID":"' + row.FItemID + '","mSystemAppID":"' + parent.window.getSystemAppID() + '"}]';
                        $.post("/coupon/PromotionCheck", { json: jsonstr }, function (data) {
                            var ret = mini.decode(data);
                            if (ret.status == 1) {
                                mini.showTips({ content: ret.msg, state: "success", x: "center", y: "top", timeout: 3000 });
                            }
                            else {
                                mini.alert("审核失败:" + ret.error);
                            }
                            grid.reload();
                        });
                    }
                });
            }
    }

    function stop() {
        var grid = mini.get("datagrid1");
        var row = grid.getSelected();
        if (row) {
            mini.confirm("是否停止选中方案？", "提示",
                function (action) {
                    if (action == "ok") {
                        var jsonstr = '[{"FItemID":"' + row.FItemID + '","mSystemAppID":"' + parent.window.getSystemAppID() + '"}]';
                        $.post("/coupon/PromotionStop", { json: jsonstr }, function (data) {
                            var ret = mini.decode(data);
                            if (ret.status == 1) {
                                mini.showTips({ content: ret.msg, state: "success", x: "center", y: "top", timeout: 3000 });
                            }
                            else {
                                mini.alert("停止失败:" + ret.error);
                            }
                            grid.reload();
                        });
                    }
                });
        } else {
            mini.alert("请选中一条记录");
        }
    }

</script>